import 'package:flutter/material.dart';
import 'package:top_foundation/utils/theme/button.dart';
import 'package:top_foundation/utils/theme/theme.dart';
import 'package:whale/helper/utils/util.dart';
import 'package:whale/pages/paint_demo/widgets/sign.dart';
import 'package:whale/pages/paint_demo/widgets/water_marker.dart';

import 'index.dart';
import 'widgets/widgets.dart';

class PaintDemoPage extends GetView<PaintDemoController> {
  const PaintDemoPage({Key? key}) : super(key: key);

  Widget _title(String data) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Text(
        data,
        style: TextStyle(
          color: ITheme.titleColor,
          fontSize: 17.sp,
          height: 2,
        ),
      ),
    );
  }

  // 主视图
  Widget _buildView() {
    final state = controller.state;
    return ListView(
      children: [
        _title('一、水印'),
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                IButton.text(
                    onPressed: controller.pickWaterImage,
                    text: '选择图片',
                    height: 30,
                    width: 80,
                    textStyle: TextStyle(
                      color: ITheme.selectedColor,
                      fontSize: 16.sp,
                    )),
                IButton.text(
                    onPressed: controller.addWaterText,
                    text: '添加水印',
                    height: 30,
                    width: 80,
                    textStyle: TextStyle(
                      color: ITheme.selectedColor,
                      fontSize: 16.sp,
                    )),
              ],
            ),
            if (state.waterImage != null) ...[
              WaterMarker(
                  repaintKey: state.waterKey,
                  img: state.waterImage!,
                  text: state.text ?? ''),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: IButton.text(
                  onPressed: controller.saveWater,
                  text: '导出',
                  textStyle: TextStyle(
                    color: Colors.white,
                    fontSize: 16.sp,
                  ),
                  backgroundColor: ITheme.selectedColor,
                  width: 80,
                  height: 32,
                ),
              ),
            ]
          ],
        ),
        _title('二、签名板'),
        SignBoard(),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<PaintDemoController>(
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: const Text("paint_demo")),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
